if exists (select 1 from sysobjects where name = 'get_persondiversrow' and type = 'P')
begin
   drop procedure get_persondiversrow
   print 'Procedure: get_persondiversrow deleted ...'
end
go
create procedure get_persondiversrow(
  @prsid      int = 1,
  @von        varchar(8) ='00000000',
  @bis        varchar(8) ='00000000',
  @jahr       int = 2008
)
as
begin
  set nocount on

  declare @dtVon datetime
  declare @dtBis datetime
  select @dtVon = convert(datetime, @von, 112)
  select @dtBis = convert(datetime, @bis, 112)

  select p.Vorname,
         p.Nachname,
         ap.Name,
         sa.Datum,
         sa.Stunden,
         sa.Grund
    from Saldoanpassung sa
    left outer join ArbeitsPlan ap
      on ap.PlanID = sa.PlanID
    left outer join Person p
      on p.PrsId = sa.PrsID
   where sa.PrsID = @prsid
     and sa.Datum between @dtVon and @dtBis

end
go
print 'Procedure: get_persondiversrow done ...'
go

grant exec on get_persondiversrow to prsadmins with grant option
go
grant exec on get_persondiversrow to prsusers
go

